<!DOCTYPE html>
<html>

	<head>
		<meta charset="utf-8">
		<title>Hello MUI</title>
		<meta name="viewport" content="width=device-width, initial-scale=1,maximum-scale=1,user-scalable=no">
		<meta name="apple-mobile-web-app-capable" content="yes">
		<meta name="apple-mobile-web-app-status-bar-style" content="black">
		<link rel="stylesheet" href="../../css/mui.min.css">
		<link rel="stylesheet" href="../css/index.css" />
		<style>
			.list-content .info .ellipsis:last-child,
			.list-content .info .ellipsis:first-child {
				width: 50%;
			}
			.fqyy{
				display: none;
			}
		</style>
	</head>

	<body>
		<!--下拉刷新容器-->
		<div id="pullrefresh" class="mui-content mui-scroll-wrapper">
			<div class="mui-scroll">
				<!--数据列表-->
				<ul class="mui-table-view" id="show">
					<li class="mui-table-view-cell" v-for="item in jsonData" v-gesture:tap.stop.prevent="change($index)">
						<a class="mui-navigate-right">
							<div class="list-content">
								<h5 class="ellipsis">商机名称:{{item.B_name}}</h5>
								<i class="line"></i>
								<div class="info">
									<span class="ellipsis">
			                  			筛选结果：<i style="color: #3A6C92;">{{item.B_status|pdzt}}</i>
			                  		</span>
									<span class="ellipsis">
			                  			日期：{{item.B_datetime}}
			                  		</span>
								</div>
								<span class="ellipsis msg" class="fq" v-show="item.B_status>2">
									放弃原因:{{item.B_giveupcause}}
								</span>
							</div>
						</a>
					</li>
				</ul>
			</div>
		</div>
		<script src="../../js/mui.min.js"></script>
		<script type="text/javascript" src="../../js/vue.js"></script>
		<script type="text/javascript" src="../../js/evalHttp.js"></script>
		<script type="text/javascript" src="../../lease/js/vue-gesture.js"></script>
		<script type="text/javascript" src="../../js/jquery.min.js" ></script>
		<script type="text/javascript" src="../js/pageFilter.js"></script>
		<script>
		mui(".mui-table-view")[0].style.display = "none";
			var app = {
					datas: {
						vm: null,
						data: {
							jsonData: []
						},
						params: {},
						changeIndex:0,
						isDown:false
					},
					methods: {
						change: function(index) {
							var items = app.datas.data.jsonData[index];
							app.datas.changeIndex = index;
							console.log(items.B_status)
							var btns = [{
								title: "派单"
							}, {
								title: "转单"
							}, {
								title: "放弃"
							},
							 {
								title: "未筛选"
							}];
							var el = items.B_status-1>=0?items.B_status-1:3;
							
							btns[el].title += "<当前状态>";
							plus.nativeUI.actionSheet(
								{
									title: "请选择操作类型",
									cancel: "取消",
									buttons: btns
								},function(e){
									if(e.index>0&&e.index<4&&e.index-el!=1){
										if(e.index==3){
											plus.nativeUI.prompt("放弃派单！\r\n没有输入放弃原因视为放弃操作",function(e){
												if(e.index==0){
													if(e.value.trim()==""){
														plus.nativeUI.toast("放弃原因没有输入,放弃操作");
														return;
													}else{
														app.datas.params.B_giveupcause = e.value;
														go();
													}
												}else{
													plus.nativeUI.toast("操作放弃");
												}
											},"请输入放弃原因",["确定放弃","取消"],"请输入放弃原因");
										}else if(e.index-el!=1){
											go();
										}
										function go(){
											plus.nativeUI.showWaiting("修改状态中...");
											app.datas.params.B_status=e.index;
											app.datas.params.ID = items.ID;
											console.log(JSON.stringify(app.datas.params));
											Xeval.Http(Xeval.Mode.HTTP_ART_UPDATA_PD_STATA,app.datas.params,app.methods._HTTP_CB_UPDATA);
										}
									}else if(e.index==4){
										plus.nativeUI.toast("不能选择此操作");
									}else if(e.index==el+1){
										plus.nativeUI.toast("当前已经是:"+btns[el].title);
									}
								});
					},
				_HTTP_CB_LISTENER: function(isOk, data) {
					console.log(JSON.stringify(data));
					mui('#pullrefresh').pullRefresh().endPulldownToRefresh();
					mui('#pullrefresh').pullRefresh().endPullupToRefresh();
					if(isOk) {
						if(data.state == 1) {
							mui(".mui-table-view")[0].style.display = "block";
							if(data.data.length > 0) {
								var arr = app.datas.data.jsonData;
								if(app.datas.isDown){
									app.datas.data.jsonData = data.data;
								}else{
									app.datas.data.jsonData = arr.concat(data.data);
								}
							} else {
								mui('#pullrefresh').pullRefresh().endPullupToRefresh(true);
								app.datas.params.page -= 1;
								plus.nativeUI.toast("没有更多数据了");
								
							}
						} else {
							plus.nativeUI.toast(data.msg);
						}
					} else {
						plus.nativeUI.alert("网络错误，请检查您的网络！");
					}
				},
				pullupRefresh: function() {
					app.datas.isDown  = false;
					app.datas.params.page++;
					Xeval.Http(Xeval.Mode.HTTP_ART_GET_SX, app.datas.params,app.methods._HTTP_CB_LISTENER);
				},
				pulldownRefresh:function(){
					app.datas.isDown  = true;
					app.datas.params.page=1;
					Xeval.Http(Xeval.Mode.HTTP_ART_GET_SX, app.datas.params,app.methods._HTTP_CB_LISTENER);
				},
				_HTTP_CB_UPDATA:function(isOk,data){
					plus.nativeUI.closeWaiting();
					if(isOk){
						if(data.state>0||data.state<4){
							app.datas.data.jsonData[app.datas.changeIndex].B_status = data.state;
							plus.nativeUI.alert("操作完成");
						}else{
							plus.nativeUI.alert(data.msg);
						}
					}
				},
				search:function(){
					var data = JSON.parse(localStorage.getItem("search"));
					localStorage.setItem("search",null);
					app.utils.getToken();
					for(var item in data){
						var　value = data[item];
						if(value != ""){
							app.datas.params[item]= value;
						}
					}
					app.methods.pulldownRefresh();
					
				}
			},
			utils:{
					getToken: function() {
						const jsonData = JSON.parse(localStorage.getItem("art_user"));
						app.datas.params = {
							Username: jsonData.data.T_accountnumber,
							Token: jsonData.guid,
							UserID: jsonData.data.T_UserID,
							page: 0,
							rows: 6
						}
					}
				},
				init: function() {
					app.datas.vm = new Vue({
						el: ".mui-table-view",
						data: app.datas.data,
						methods: app.methods
					})
					app.utils.getToken();
					app.methods.pullupRefresh();
				}
			}
			mui.plusReady(function() {
				Xeval.setUrl(Xeval.UrlModel.CRM)
				app.init();
			})
			mui.init({
				pullRefresh: {
					container: '#pullrefresh',
					up: {
						callback: app.methods.pullupRefresh
					},
					down:{
						callback: app.methods.pulldownRefresh
					}
				}
			});
		</script>
	</body>

</html>